package com.neiquan.weiguan.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.neiquan.weiguan.R;
import com.neiquan.weiguan.activity.ContainerActivity;
import com.neiquan.weiguan.activity.MainActivity;
import com.neiquan.weiguan.fragment.VideoDetailsFragment;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMVideo;
import com.umeng.socialize.media.UMusic;
import com.umeng.socialize.utils.Log;

import net.neiquan.applibrary.wight.CircleImageView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;

/**
 * Created by wyl on 2016/6/24.
 * 视屏列表界面
 */
public class VideoListAdapter extends MyBaseAdapter<String> implements UMShareListener {

    private Context context;
    private List<String> strings;

    public VideoListAdapter(Context context, List<String> data) {
        super(context, data);
        this.context = context;
        this.strings = strings;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_videolist_item, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.mVideoplayer.setUp("http://2449.vod.myqcloud.com/2449_43b6f696980311e59ed467f22794e792.f20.mp4",
                "http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640",
                "一行代码实现视频播放");
        viewHolder.mVideolistItemForwarding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.info_icon_1);
                UMImage image = new UMImage(context, "http://www.umeng.com/images/pic/social/integrated_3.png");
                //UMImage image = new UMImage(ShareActivity.this,bitmap);
                //UMImage image = new UMImage(ShareActivity.this,new File("/SDCARD/image_jpg.jpg"));

                UMusic music = new UMusic("http://music.huoxing.com/upload/20130330/1364651263157_1085.mp3");
                //UMusic music = new UMusic("http://y.qq.com/#type=song&mid=002I7CmS01UAIH&tpl=yqq_song_detail");
                music.setTitle("This is music title");
                music.setThumb("http://www.umeng.com/images/pic/social/chart_1.png");
                music.setDescription("my description");
                // share video
                UMVideo video = new UMVideo("http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html");
                video.setThumb("http://www.adiumxtras.com/images/thumbs/dango_menu_bar_icon_set_11_19047_6240_thumb.png");
                // share URL
                String url = "http://www.umeng.com";
                /**shareboard  need the platform all you want and callbacklistener,then open it**/
                new ShareAction((MainActivity) context).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.WEIXIN_FAVORITE)
                        .withText("来自友盟分享面板")
                        .withMedia(image)
                        .setCallback(VideoListAdapter.this)
                                //.withShareBoardDirection(v, Gravity.TOP | Gravity.LEFT)
                        .open();
            }
        });
        viewHolder.mVideoplayer.setOnClickVideoPlayerListener(new JCVideoPlayer.OnClickVideoPlayerListenerSimple() {
            @Override
            public boolean onPlay(JCVideoPlayer jcVideoPlayer) {
                Intent intent = new Intent();
//              intent.putExtra("video", strings.get(position));
                ContainerActivity.startActivity(context, VideoDetailsFragment.class, intent);
                return false;
            }
        });
    }

    @Override
    public int getItemCount() {
        return 5;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.videoplayer)
        JCVideoPlayer mVideoplayer;
        @InjectView(R.id.videolist_item_userimage)
        CircleImageView mVideolistItemUserimage;
        @InjectView(R.id.videolist_item_username)
        TextView mVideolistItemUsername;
        @InjectView(R.id.videolist_item_forwarding)
        ImageView mVideolistItemForwarding;
        @InjectView(R.id.videolist_item_speak_count)
        TextView mVideolistItemSpeakCount;
        @InjectView(R.id.videolist_item_lin)
        FrameLayout mVideolistItemLin;
        @InjectView(R.id.videolist_item_text_count)
        TextView mVideolistItemTextCount;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    @Override
    public void onResult(SHARE_MEDIA platform) {
        Log.d("plat", "platform" + platform);
        if (platform.name().equals("WEIXIN_FAVORITE")) {
            Toast.makeText(context, platform + " 收藏成功啦", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onError(SHARE_MEDIA platform, Throwable throwable) {
        Toast.makeText(context, platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCancel(SHARE_MEDIA platform) {
        Toast.makeText(context, platform + " 分享取消了", Toast.LENGTH_SHORT).show();
    }


}
